<?php
namespace app\admin\model;
use think\Model;

class SystemParam extends Model {
	
	protected $name = 'system_param'; 	 //表名
	protected $pk = 'param_id';  	//主键		
	protected $autoinc  = true;	 	//主键是否自动增长类型
   
	//获取当前用户的授权信息
	public function getParam(){
		$data = $this->field("
			param_id,
			param_scope,
			param_scope_sort, 
			param_type,
			param_code, 
			param_name, 
			param_des,
			page_url,
			page_size
		") ->order("create_time asc") ->select();
		
		//获取参数范围并去重
		$paramScope=array();
		foreach ($data as $value){
			$paramScope[] = $value['param_scope'];
		}
		$paramScope = array_unique($paramScope);
		
		//范围分类
		$result = array();
		foreach ($paramScope as $key => $scopeValue){
			
			//先取范围分类去重
			$paramScopeSort=array();
			foreach ($data as $value){
				if($value["param_scope"] == $scopeValue){
					$paramScopeSort[] = $value['param_scope_sort'];
				}
			}
			$paramScopeSort = array_unique($paramScopeSort);
			
			//在范围分类数据
			$paramScopeSortData=array();
			foreach ($paramScopeSort as $sortVal){
				$arr=array();
				foreach ($data as $value){
					if($value["param_scope_sort"] == $sortVal && $value["param_scope"] == $scopeValue){
						array_push($arr, $value);
					}
				}
				$paramScopeSortData[]=array( "$sortVal" =>$arr);
			}
			
			$result[] = array( "$scopeValue" =>$paramScopeSortData);
		}	
			
		return $result;	
	}
	
}